package com.saxon.springboot.Controller;

import com.saxon.springboot.config.i18n;
import com.saxon.springboot.config.myInterceprter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MymvcConfiguration implements WebMvcConfigurer {
    //视图解析viewcontroller
    @Override
    public void addViewControllers (ViewControllerRegistry registry) {
        registry.addViewController ("/").setViewName ("index");
        registry.addViewController ("/index.html").setViewName ("index");
        registry.addViewController ("/main.html").setViewName ("dashboard");
    }

    //国际化
    @Bean
    public LocaleResolver localeResolver () {
        return new i18n ();
    }
    //拦截器实现登陆拦截

    @Override
    public void addInterceptors (InterceptorRegistry registry) {
        registry.addInterceptor (new myInterceprter ())
                .addPathPatterns ("/**") //添加拦截的路径
                .excludePathPatterns ("/index.html","/login","/");//通过的请求
    }
}
